package com.jzh.selfwallpaper.view.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.jzh.selfwallpaper.R;
import com.jzh.selfwallpaper.constant.Constant;
import com.jzh.selfwallpaper.model.Model;
import com.jzh.selfwallpaper.util.ScreenUtil;
import com.jzh.selfwallpaper.view.widget.Model_1;
import com.jzh.selfwallpaper.view.widget.Model_2;
import com.jzh.selfwallpaper.view.widget.Model_3;

public class ScreenShootActivity extends BaseActivity {

    //调用系统相册-选择图片
    private static final int IMAGE = 1;
    private LinearLayout root_view;
    //壁纸编号
    private int model_number = -1;
    private Model model;

    @Override
    public void widgetClick(View v) {

    }

    @Override
    protected void init() {

        model_number = getIntent().getIntExtra(Constant.MODEL_NUMBER, -1);
    }

    @Override
    public View bindView() {
        ScreenUtil.hideBottomUIMenu(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_screen_shoot;
    }

    @Override
    public void initView(View view) {

        root_view = findViewById(R.id.root_view);
        switch (model_number){
            case 0x001:
                model = new Model_1(this);
                break;
            case 0x002:
                model = new Model_2(this);
                break;
            case 0x003:
                model = new Model_3(this);
                break;
        }
        root_view.addView((View) model);

    }

    @Override
    public void setListener() {

    }

    @Override
    public void doBusiness(Context mContext) {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //获取图片路径
        if (requestCode == IMAGE && resultCode == Activity.RESULT_OK && data != null) {
            Uri selectedImage = data.getData();
            String[] filePathColumns = {MediaStore.Images.Media.DATA};
            Cursor c = getContentResolver().query(selectedImage, filePathColumns, null, null, null);
            c.moveToFirst();
            int columnIndex = c.getColumnIndex(filePathColumns[0]);
            String imagePath = c.getString(columnIndex);
            Log.i("mkmkmk", imagePath);
            if (model != null) {
                model.setPhoto(imagePath);
            }
            c.close();
        }
    }
}
